﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Helpers;
using iDMS.Models;

namespace iDMS.Controllers
{
    public class HomeController : Controller
    {
        private DMSRepository db = new DMSRepository();
        public ActionResult Index()
        {

            ViewBag.Message = "Welcome to ASP.NET MVC!";
            ViewBag.Menuitems = "xxx";
            ViewBag.Phases = db.PhasesGetAll().ToList();
            return View();
        }

        [CustomAuthorize(Roles = "Administrator")]
        public ActionResult SendMail()
        {
            
            try
            {
                WebMail.Send("mariusz.wincior@gmail.com", subject: "Test",body: "Manufacturer xxx has been changed");
                ViewBag.Message = "Mail was Sent"; 
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.ToString();
                //ViewData.ModelState.AddModelError("_FORM", ex.ToString());
            }
            
            return View("Index");
        }

        public ActionResult About()
        {
            Version version = typeof(iDMS.Controllers.HomeController).Assembly.GetName().Version;
            ViewBag.Version = version.ToString();
            ViewBag.Processor = typeof(iDMS.Controllers.HomeController).Assembly.GetName().ProcessorArchitecture.ToString();
            ViewBag.OSVersion = Environment.OSVersion.ToString();
            ViewBag.Packages = db.SoftwarePackagesGetAll().ToList();
            DateTime date = new DateTime(2000, 1, 1).AddDays(version.Build).AddSeconds(version.Revision * 2);
            ViewBag.BuildDate = date.ToString(); ;
            return View();
        }
    }
}
